package gui;

import java.awt.ItemSelectable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle;
import javax.swing.ListModel;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import main.ToEngineFacade;


/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class SectionChooser extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JButton btnCancel;
	//private JPanel pnl;
	private JScrollPane jScrollPane1;
	private JList lstItems;
	private JButton btnOk;
	private ToEngineFacade toEngingFacade;

	public SectionChooser(Vector<String> list, ToEngineFacade toEngFacade) {
		super();
		this.toEngingFacade = toEngFacade;
		initGUI(list);
	}

	private void initGUI(Vector<String> list) {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			
			{
				btnOk = new JButton();
				btnOk.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
				btnOk.setForeground(new java.awt.Color(204, 0, 51));
				btnOk.setText("OK!");
				btnOk.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						String item = (String)lstItems.getSelectedValue();
						if (item!=null){
							toEngingFacade.loadPreviousGraph(item);
						} else {
							System.out.println("SectionChooser, btnOkActionPerformed - no item selected");
						}
						dispose();
					}
				});
			}
			{
				jScrollPane1 = new JScrollPane();
				
				{
					ListModel lstItemsModel = 
						new DefaultComboBoxModel(list);
					//pnl=new JPanel();
					lstItems = new JList();
					
					jScrollPane1.setViewportView(lstItems);
					//pnl.add(jScrollPane1);
					lstItems.setModel(lstItemsModel);
					//this.add(pnl);
				}
			}
			{
				btnCancel = new JButton();
				btnCancel.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
				btnCancel.setForeground(new java.awt.Color(204, 0, 51));
				btnCancel.setText("Cancel");
				btnCancel.addActionListener(new ActionListener(){
					@Override
					public void actionPerformed(ActionEvent e) {
						dispose();
					}
				});
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
			.addContainerGap(48, 48)
			.addComponent(jScrollPane1, 0, 133, Short.MAX_VALUE)
			.addGap(31)
			.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
			    .addComponent(btnCancel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
			    .addComponent(btnOk, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
			.addContainerGap(25, 25));
		thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(70, 70)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(btnCancel, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE)
				        .addGap(106)
				        .addComponent(btnOk,GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE))
				    .addComponent(jScrollPane1, GroupLayout.Alignment.LEADING, 0, 278, Short.MAX_VALUE))
				.addContainerGap(44, 44));
			pack();
			setSize(400, 300);
			this.getContentPane().setBackground(new java.awt.Color(3, 141, 187));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
